using System;
using System.IO;

namespace DeploymentWang.Core
{
    /// <summary>
    /// 
    /// </summary>
    public class SmartLocation
    {
        /// <summary>
        /// Default ctor
        /// </summary>
        public SmartLocation()
        {
        }

        /// <summary>
        /// ctor overload - allows initial location to be set
        /// </summary>
        /// <param name="rawLocation"></param>
        public SmartLocation(string rawLocation) 
            : this()
        {
            RawLocation = rawLocation;
        }

        /// <summary>
        /// The unresolved location 
        /// </summary>
        public string RawLocation { get; set; }

        /// <summary>
        /// The resolved location. If the <see cref="RawLocation"/> is not rooted
        /// then the fully qualified path will be resolved relative to the executing 
        /// assembly path.
        /// </summary>
        public string Location
        {
            get
            {
                string location = RawLocation;

                if (!Path.IsPathRooted(RawLocation))
                {
                    // non-web context
                    location = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, RawLocation);
                }

                return location;
            }
        }
    }
}